import { defineConfig } from '@vben/vite-config';

// 自动引入api
import AutoImport from 'unplugin-auto-import/vite';
import ElementPlus from 'unplugin-element-plus/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';

export default defineConfig(async () => {
  return {
    application: {},
    vite: {
      plugins: [
        ElementPlus({
          format: 'esm',
        }),
        AutoImport({
          imports: ['vue', 'vue-router', 'pinia'], // 自动引入Vue常用API
          dts: 'src/type/auto-imports.d.ts', // 生成类型声明文件
          vueTemplate: true, // 支持在Vue模板中自动引入
          resolvers: [ElementPlusResolver()],
        }),
        Components({
          collapseSamePrefixes: true, // 合并相同前缀的组件
          directoryAsNamespace: true, // 目录作为命名空间
          dts: 'src/type/auto-components.d.ts', // 生成类型声明文件
          resolvers: [ElementPlusResolver()],
        }),
      ],
      server: {
        proxy: {
          '/api': {
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, ''),
            // mock代理目标地址
            target: 'http://117.72.173.188:8080/api',
            ws: true,
          },
        },
      },
    },
  };
});
